package com.hk.service.impl;

import com.github.pagehelper.PageHelper;
import com.hk.mapper.ICompanyMessageMapper;
import com.hk.model.CompanyMessage;
import com.hk.service.ICompanyMessageService;
import com.hk.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @Author: zhe
 * @Date: 2021/6/11 15:12
 * @Statement: 公司简介Service层
 */
@Service
public class CompanyMessageServiceImpl implements ICompanyMessageService {

    @Autowired
    private ICompanyMessageMapper iCompanyMessageMapper;

    @Override
    public List<CompanyMessage> findAll(Integer page, Integer limit, CompanyMessage companyMessage) {
        PageHelper.startPage(page,limit);
        List<CompanyMessage> companyMessageList = iCompanyMessageMapper.findAll(companyMessage);
        return companyMessageList;
    }
    

    @Override
    public int count(Integer page, Integer limit, CompanyMessage companyMessage) {
//        PageHelper.startPage(page,limit);
        int count = iCompanyMessageMapper.count(companyMessage);
        return count;
    }

    @Override
    public CompanyMessage findById(Integer id) {
        CompanyMessage companyMessage = iCompanyMessageMapper.findById(id);
        return companyMessage;
    }

//    查询使用的公司信息
    @Override
    public CompanyMessage findByState(CompanyMessage companyMessage) {
        CompanyMessage companyMessage1 = iCompanyMessageMapper.findByState(companyMessage);
        return companyMessage1;
    }

    @Override
    public int save(CompanyMessage t) {
        String dateTimeString = DateUtils.dateTimeString(new Date());
        t.setGmtCreate(dateTimeString);
        t.setGmtModified(dateTimeString);
        int save = iCompanyMessageMapper.save(t);
        if (save == 1) {
            System.out.println("公司信息添加成功！");
        }
        return save;
    }

    @Override
    public int update(CompanyMessage t) {
        String dateTimeString = DateUtils.dateTimeString(new Date());
        t.setGmtModified(dateTimeString);
        int update = iCompanyMessageMapper.update(t);
        if (update == 1) {
            System.out.println("当前公司信息修改成功！");
        }
        return update;
    }

    @Transactional
    @Override
    public int updateState(CompanyMessage companyMessage) {
        String dateTimeString = DateUtils.dateTimeString(new Date());
        companyMessage.setGmtModified(dateTimeString);
        int i1 = iCompanyMessageMapper.updateState1();
        int i = iCompanyMessageMapper.updateState(companyMessage);
        if (i1 >=1 && i == 1) {
            System.out.println("当前公司信息状态修改完成！");
        }
        return i;
    }

    @Override
    public int delete(Integer id) {
        int delete = iCompanyMessageMapper.delete(id);
        if (delete == 1) {
            System.out.println("当前公司信息删除成功！");
        }
        return delete;
    }

}
